//这个文件专门用来存放关于列表的所有接口
const Router = require('koa-router')
const video = new Router()
const db = require('../util/db')
const bodyparser = require('koa-bodyparser')
video.use(bodyparser())//调用这个中间件 就可以拿到前端post过来的数据

//写对应的接口
video.get('/interactive_Video', async (ctx) => {
    console.log('---------------------')
    console.log(ctx.originalUrl)
    const obj = ctx.query
    var str = 'where '
    for (key in obj) {
        var name = `${key}='${obj[key]}' and `
        str += name
    }
    let searchSql = 'select * from interactive_video '+str.slice(0,-4)
    let result= await new Promise((resolve, reject) => {
        return db.query(searchSql, (err, data) => {
            if (err) {
                throw err;
                
            } 
            console.log(data)
            resolve(data)//扔出去一个数组
        })
    })
    ctx.body = result;
    console.log('---------------------')
})

module.exports=video